extend ./layout/default

block link
  link(rel="stylesheet" href="/static/css/editProfile.css")
block main-content
  #profileForm
    h2 Sign up
    .breakline  
    p
      input.email(type="email" placeholder="your company email")
    p
      input.name(placeholder="username")
    p 
      input.company(type="text" placeholder="company")
    p
      input.password(type="password" placeholder="password")
    p
      input.password#confirmpwd(type="password" placeholder="confirmed password")
    
    .error
    button#submitProfile(type="submit" style="background-color: #274;text-align: center;") submit
    
  script.
    $('#submitProfile').click(function(){
      var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;  
      var email = $('.email').val()
      var username = $('.name').val().trim()
      var company = $('.company').val().trim()
      var password = $('.password').val()
      if(!re.test(email)){
        $("input").val("")
        return $(".error").html("请使用合法的邮箱")
      }
      if(username.length<3 || username.length > 10){
        return $(".error").html("用户名长度范围3-10")
      }
      if(password.length<6 || password.length>20){
        return $(".error").html("密码长度范围6-20")
      }
      
      if ($('.password').val() != $('#confirmpwd').val()){
        $("input").val("")
        return $(".error").html("两次输入的密码不同")
      }
      $.post('/register', {username:username, company:company, email:email, password:password}, function(data){
        if(data.status === 'ok'){
          console.log("ok")
          location.href = "/notify/unactived"
        }else{
          $(".error").html(data.status)
        } 
      })
    })
